# A very rough  method to group the counties.
# The # of wells drilled each year:
# >50: shale core, flag = 2
# >5: shale effected, flag = 1
# <5: shale not effected, flag = 0
# Assumption: single direction evolution: 0 -> 1 -> 2, once the county is in category 2, it can never be in 0 or 1.

BEGIN {
  FS = ","
  OFS = ","
  flag = 0
}

{
  if (flag >= 1) {
    if ($3 == 2001)
      flag = 0
    else {
      if ($5 >= 50)
        flag = 2
      print flag, $0
      next
    }
  }

  if ($5 >= 5) {
    flag = 1
    if ($5 >= 50)
      flag = 2
    }
  print flag, $0
}
